package com.richinfo.exception;


import com.richinfo.util.RespCodeEnum;

/**
 * 默认不进行堆栈追踪，设置writableStackTraceDefualt为true开启堆栈追踪功能.
 */
public class BaseRuntimeException extends RuntimeException {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1093814904862066668L;

	protected static boolean writableStackTraceDefualt = false;

	private String code = "999999";

	public BaseRuntimeException(RespCodeEnum codeEnum){
		this(codeEnum.getCode(),codeEnum.getDesc());
	}
	
	public BaseRuntimeException() {
		this(null, null, null);
	}

	/**
	 * @param message
	 *            异常信息
	 */
	public BaseRuntimeException(String message) {
		this(null, message, null);
	}

	/**
	 * @param code
	 *            异常码
	 * @param message
	 *            异常信息
	 */
	public BaseRuntimeException(String code, String message) {
		this(code, message, null);
	}

	/**
	 * @param code
	 *            异常码
	 * @param message
	 *            异常信息
	 */
	public BaseRuntimeException(int code, String message) {
		this(String.valueOf(code), message, null);
	}

	/**
	 * @param cause
	 *            引起此异常的原因
	 */
	public BaseRuntimeException(Throwable cause) {
		this(null, null, cause);
	}

	/**
	 * @param message
	 *            异常信息
	 * @param cause
	 *            引起此异常的原因
	 */
	public BaseRuntimeException(String message, Throwable cause) {
		this(null, message, cause);
	}

	/**
	 * @param code
	 *            异常码
	 * @param message
	 *            异常信息
	 * @param cause
	 *            引起此异常的原因
	 */
	public BaseRuntimeException(String code, String message, Throwable cause) {
		this(code, message, cause, false);
	}

	/**
	 * @param code
	 *            异常码
	 * @param message
	 *            异常信息
	 * @param cause
	 *            引起此异常的原因
	 */
	public BaseRuntimeException(int code, String message, Throwable cause) {
		this(String.valueOf(code), message, cause, writableStackTraceDefualt);
	}

	/**
	 * @param code
	 *            异常码
	 * @paramm message 异常信息
	 * @param cause
	 *            引起此异常的原因
	 * @param writableStackTrace
	 *            是否开启堆栈追踪功能，默认为false
	 */
	protected BaseRuntimeException(String code, String message, Throwable cause, boolean writableStackTrace) {
		super(message, cause, true, writableStackTrace);

		this.code = code;
	}

	public String getCode() {
		return code;
	}

}
